package com.youxue.teachin.common.utils;

import com.library.rest.rxjava.ServerException;

/**
 * @author from.clean
 * @version 1.0.0
 *
 * @param <T> domain object
 * Default subscriber base class to be used whenever you want default error handling.
 */
public class DefaultSubscriber<T> extends rx.Subscriber<T> {
    @Override
    public void onCompleted() {
        // no-op by default.
    }

    @Override
    public void onError(Throwable e) {
        // no-op by default.
        if (e instanceof ServerException) {
            ServerException serverException = (ServerException)e;
            new SystemErrorHandler().handle(serverException.code, serverException.message);
        }
        e.printStackTrace();
    }

    @Override
    public void onNext(T t) {
        // no-op by default.
    }

    protected String getErrorMessage(Throwable e) {
        return e.getMessage();
    }
}
